((win) => {

    class RSA {

        constructor() {

        }

        // 服务端公钥
        getServerPublicKey() {
            return KEY.serverPublicKey;
        }

        // 客户端私钥
        getClientPrivateKey() {
            return KEY.clientPrivateKey;
        }

        // 公钥加密
        encrypt(data, publicKey) {
            let that = this;
            let encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey || that.getServerPublicKey());
            return encrypt.encrypt(data);
        }

        // 私钥解密
        decrypt(data, privateKey) {
            let that = this;
            let decrypt = new JSEncrypt();
            decrypt.setPrivateKey(privateKey || that.getClientPrivateKey());
            return decrypt.decrypt(data);
        }

        // 签名
        sign(data, privateKey) {
            let that = this;
            let jsEncrypt = new JSEncrypt();
            jsEncrypt.setPrivateKey(privateKey || that.getClientPrivateKey());
            return jsEncrypt.sign(data, CryptoJS.SHA1, "sha1");
        }

        // 验签
        signVerify(data, sign, publicKey) {
            let that = this;
            let jsEncrypt = new JSEncrypt();
            jsEncrypt.setPublicKey(publicKey || that.getServerPublicKey());
            return jsEncrypt.verify(data, sign, CryptoJS.SHA1);
        }

    }

    win.RSA = RSA;

})(window);
